package com.lbj.mvvm.livedata.bus

import androidx.lifecycle.MutableLiveData

/**
 * 作者：李炳军
 * 创建日期：2021-04-01  16:28
 * 释义：
 */

object LiveDataBus {
    private val bus = HashMap<String, MutableLiveData<Any>>()

    fun <T> set(key: String, type: Class<T>): MutableLiveData<T> {
        if (!bus.containsKey(key)) {
            bus[key] = MutableLiveData()
        }
        return bus[key] as MutableLiveData<T>
    }

    fun set(key: String): MutableLiveData<Any> {
        return set(key, Any::class.java)
    }
}